<%@ page contentType="text/html; charset=Windows-31J" language="java" %>
<%@ include file="../inc/common.jsp" %>

<html:html locale="true">
<HEAD>
	<html:base/>
	<META http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
	<TITLE><%=Globals.get("WEB_PAGETITLE")%></TITLE>
	<script language="javaScript">
		function rst() {
			date1 = new Date();
			y1 = date1.getFullYear();
			m1 = date1.getMonth()+1;
			d1 = date1.getDate();
			w0=0;
			date3=new Date(y1,m1-1,1);
			for(i=1;i<=d1;i++){
				date3.setDate(i);
				if(date3.getDay() == 5) w0++;
			}
			w1=w0;
		}
		rst();
		function setYear(year) {
			y1=year;
			wday_search();
		}
		function setMonth(month) {
			m1=month;
			wday_search();
		}
		function setWeek(week) {
			w1=week;
			wday_search();
		}
		function wday_search() {
			date2 = new Date(y1,m1-1,1);
			getMaxDay(y1,m1-1);
			w=1;
			//1日が土曜日の月の場合
			if (w1 == 1 && date2.getDate() == 1 && date2.getDay() == 6) {
				date2 = new Date(y1,m1-2,1);
				getMaxDay(y1,m1-2);
				w1=5;
			}else if (w1 >= 2 && date2.getDate() == 1 && date2.getDay() == 6) {
				w1=w1-1;
			}
			for(i=1;i<=maxDay;i++){
				date2.setDate(i);
				if (date2.getDay() == 5 && w1 == w) break;
				else if (date2.getDay() == 5 && w1 != w) w++;
			}
			if (date2.getDay() == 5 && w1 == w) {
				endYear = date2.getFullYear();
				endMonth = date2.getMonth()+1;
				endDay = date2.getDate();
				date2.setDate(endDay-6);
				startYear = date2.getFullYear();
				startMonth = date2.getMonth()+1;
				startDay = date2.getDate();
				document.forms[0].elements[6].value = startYear;
				document.forms[0].elements[7].value = startMonth;
				document.forms[0].elements[8].value = startDay;
				document.forms[0].elements[9].value = endYear;
				document.forms[0].elements[10].value = endMonth;
				document.forms[0].elements[11].value = endDay;
			} else if (date2.getDay() != 5) {
				date2 = new Date(y1,m1,1);
				getMaxDay(y1,m1);
				w=1;
				w1=1;
				for(i=1;i<=maxDay;i++){
					date2.setDate(i);
					if (date2.getDay() == 5 && w1 == w) break;
				}
				endYear = date2.getFullYear();
				endMonth = date2.getMonth()+1;
				endDay = date2.getDate();
				date2.setDate(endDay-6);
				startYear = date2.getFullYear();
				startMonth = date2.getMonth()+1;
				startDay = date2.getDate();
				document.forms[0].elements[6].value = startYear;
				document.forms[0].elements[7].value = startMonth;
				document.forms[0].elements[8].value = startDay;
				document.forms[0].elements[9].value = endYear;
				document.forms[0].elements[10].value = endMonth;
				document.forms[0].elements[11].value = endDay;
			}
		}
		function getMaxDay(year,month) {
			var monthDay = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
			// うるう年変換（1901年から2099年まで対応）
			if (((month) == 1) && (year % 4 == 0)) {
				maxDay = 29;
			} else {
				maxDay = monthDay[month];
			}
		}
	</script>
</HEAD>
<BODY BGCOLOR=<%=Globals.get("WEB_BODY_BGCOLOR")%> LINK=<%=Globals.get("WEB_BODY_LINK")%> VLINK=<%=Globals.get("WEB_BODY_VLINK")%>>
<html:form action="/weeklyReport_add" target="sub">
<TABLE border="0">
<TR>
	<TH align="left">
		編集する週報のプロジェクト名、作業期間を選択した後、”登録ボタン”または”削除ボタン”を押してください。
	</TH>
</TR>
</TABLE>
<TABLE border="0">
<TR>
	<TD>
		<TABLE cellpadding="1" cellspacing="1" border="1">
		<TR>
			<TH ALIGN="left">ﾌﾟﾛｼﾞｪｸﾄ名</TH>
			<TD>
				<html:select property="projectId" >
					<html:options collection="projectList" property="projectId" labelProperty="name" />
				</html:select>
			</TD>
			<TH ALIGN="left">作業期間</TH>
			<TD>
				<html:select property="workDateStartY" onchange="setYear(this.options[this.selectedIndex].value)">
					<html:options name="systemCalendar" property="systemYear" labelProperty="systemYear" labelName="systemCalendar" />
				</html:select>年
				<html:select property="workDateStartM" onchange="setMonth(this.options[this.selectedIndex].value)">
					<html:options name="systemCalendar" property="systemMonth" labelProperty="systemMonth" labelName="systemCalendar" />
				</html:select>月 第
				<html:select property="workDateStartW" onchange="setWeek(this.options[this.selectedIndex].value)">
					<html:options name="systemCalendar" property="systemWeek" labelProperty="systemWeek" labelName="systemCalendar" />
				</html:select> 週
			</TD>
		</TR>
		</TABLE>
	</TD>
	<TD><html:submit property="add" value="登録" /></TD>
	<TD><html:submit property="rm" value="削除" /></TD>
</TR>
<TR>
	<TD colspan="3" ALIGN="left">
		<TABLE cellpadding="1" cellspacing="1" border="1">
		<TR>
			<TH ALIGN="left">作業期間</TH>
			<TD>
				<html:text property="workDateStartY" size="4" disabled="true" />年
				<html:text property="workDateStartM" size="2" disabled="true" />月
				<html:text property="workDateStartD" size="2" disabled="true" />日 ～　
				<html:text property="workDateEndY" size="4" disabled="true" />年
				<html:text property="workDateEndM" size="2" disabled="true" />月
				<html:text property="workDateEndD" size="2" disabled="true" />日
			</TD>
		</TR>
		</TABLE>
	</TD>
</TR>
</TABLE>
	<script language="javaScript">
			wday_search();
	</script>
</html:form>
</BODY>
</html:html>
